<div data-ng-if="md">
  <div class="btn-group md-actions"
       data-ng-if="user.isEditorOrMore()">
    <button type="button"
            id="gn-button-manage-record"
            title="{{'manageRecord' | translate}}"
            class="btn btn-default dropdown-toggle"
            data-toggle="dropdown"
            aria-label="{{'manageRecord' | translate}}"
            aria-expanded="false">
      <span class="fa fa-fw fa-cog"></span>
      <span data-translate="" class="hidden-xs">manageRecord</span>
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
      <li role="menuitem">
        <a href=""
           data-ng-if="user.canEditRecord(md) && user.isEditorOrMore() && md.draft != 'y'"
           data-ng-click="mdService.openPrivilegesPanel(md, getCatScope())">
          <span class="fa fa-fw fa-key"></span>&nbsp;
          <span data-translate="">privileges</span>
        </a>
      </li>
      <li role="menuitem"
          data-ng-if="md.isOwned() && user.isUserAdminOrMore()">
        <a href=""
           data-ng-click="mdService.openTransferOwnership(md, null, getCatScope())">
          <span class="fa fa-fw fa-user"></span>&nbsp;
          <span data-translate="">transferOwnership</span>
        </a></li>
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() || user.isReviewerForGroup(md.groupOwner)) && md.draft != 'y'"
          data-ng-class="
            (md.isPublished() || (allowPublishInvalidMd() === true) ||
            (!md.isPublished() && (allowPublishInvalidMd() === false) &&
            (!md.hasValidation() || (md.hasValidation() && md.isValid())))) ? '' : 'disabled'"
          title="{{(!md.isPublished() ? (md.isValid() ? 'mdvalid' :
            (!md.hasValidation() ? 'mdnovalidation':
            (allowPublishInvalidMd() === false ? 'mdinvalidcantpublish' : 'mdinvalid'))) : '') | translate }}">
        <a href="" data-ng-click="mdService.publish(md, undefined, undefined, getCatScope())">
          <span class="fa fa-fw"
             data-ng-class="md.isPublished() ? 'fa-lock' : 'fa-unlock'"></span>&nbsp;
          <span data-ng-if="md.isPublished()"
                data-translate="">unpublish</span>
          <span data-ng-if="!md.isPublished()"
                data-translate="">publish</span>&nbsp;

          <span class="fa fa-fw"
             data-ng-if="!md.isPublished() && md.hasValidation()"
             data-ng-class="md.isValid() ? 'gn-recordtype-n text-success' : 'gn-recordtype-n text-danger'"></span>
          <span class="fa fa-fw gn-recordtype-n text-muted"
             data-ng-if="!md.isPublished() && !md.hasValidation()"></span>
        </a>

      </li>
      <!-- TODO: Some installation only allows status update
      based on current status. -->

      <!--
        Workflow:

        Editor
        - if status is 'Draft' (mdStatus = 1) -> label = 'Submit for review'
        - if status <> 'Draft' hide the menu
        - data submitted by user - cancel approval

        Reviewer
        - 3 options in menu:
          1. Approve metadata (id = 2)
          2. Reject metadata (id = 5)
          3. Retire metadata (id = 3)
      -->
      <li role="menuitem" class="divider" data-ng-show="isMdWorkflowEnable && (md.mdStatus == 1 || md.mdStatus == 4)"></li>
      <li role="menuitem"
          class="dropdown-header"
          data-ng-show="isMdWorkflowEnable && (md.mdStatus == 1 || md.mdStatus == 4)">
        <span data-translate="">workflow</span>
      </li>
      <!-- user = editor, status = 1, statusToSelect = 4 -->
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() ||
          user.isEditorForGroup(md.groupOwner)) && md.mdStatus == 1 && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 4, 14)">
          <span class="fa fa-fw fa-file-o"></span>&nbsp;
          <span data-translate="">mdStatusTitle-14</span>
        </a>
      </li>
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() ||
          user.isEditorForGroup(md.groupOwner)) && md.mdStatus == 3 && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 1, 31)">
          <span class="fa fa-fw fa-file-o"></span>&nbsp;
          <span data-translate="">mdStatusTitle-31</span>
        </a>
      </li>
      <!-- user = editor, status = 4, statusToSelect = 1 -->
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && !user.isReviewerForGroup(md.groupOwner) &&
          user.isEditorForGroup(md.groupOwner) && md.mdStatus == 4  && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 1, 41)">
          <span class="fa fa-fw fa-undo"></span>&nbsp;
          <span data-translate="">mdStatusTitle-41</span>
        </a>
      </li>
      <!-- user = reviewer, status = 4, statusToSelect = 2 -->
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() || user.isReviewerForGroup(md.groupOwner)) &&
          md.mdStatus == 4  && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 2, 42)">
          <span class="fa fa-fw fa-thumbs-o-up"></span>&nbsp;
          <span data-translate="">mdStatusTitle-42</span>
        </a>
      </li>
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() || user.isReviewerForGroup(md.groupOwner)) &&
          md.mdStatus == 1  && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 2, 12)">
          <span class="fa fa-fw fa-thumbs-o-up"></span>&nbsp;
          <span data-translate="">mdStatusTitle-12</span>
        </a>
      </li>
      <!-- user = reviewer, status = 4, statusToSelect = 5 -->
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() || user.isReviewerForGroup(md.groupOwner)) &&
          md.mdStatus == 4  && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 1, 411)">
          <span class="fa fa-fw fa-thumbs-o-down"></span>&nbsp;
          <span data-translate="">mdStatusTitle-411</span>
        </a>
      </li>
      <!-- user = reviewer, status = 4, statusToSelect = 3 -->
      <li role="menuitem"
          data-ng-if="user.canEditRecord(md) && (user.isAdmin() || user.isReviewerForGroup(md.groupOwner)) &&
          md.mdStatus == 4  && isMdWorkflowEnable && md.isWorkflowEnabled()">
        <a href=""
           data-ng-click="mdService.openUpdateStatusPanel(getScope(), 'workflow', null, 3, 33)">
          <span class="fa fa-fw fa-archive"></span>&nbsp;
          <span data-translate="">mdStatusTitle-33</span>
        </a>
      </li>
      <li data-ng-if="isMdWorkflowEnable && user.canEditRecord(md) && !md.isWorkflowEnabled()">
        <a role="menuitem"
           href=""
           data-ng-click="mdService.startWorkflow(md, getCatScope())">
          <span class="fa fa-fw fa-code-fork"></span>&nbsp;
          <span data-translate="">enableWorkflow</span>
        </a>
      </li>

      <li role="menuitem" class="divider"
          data-ng-if="user.isConnected() && user.canEditRecord(md) && md.draft != 'y'"></li>


      <li data-ng-repeat="t in tasks"
          data-ng-show="taskConfiguration[t.name] && taskConfiguration[t.name].isVisible && taskConfiguration[t.name].isVisible(md)"
          data-ng-class="::{'disabled': !taskConfiguration[t.name].isApplicable(md)}">
        <a href="" data-ng-click="mdService.openUpdateStatusPanel(getScope(md), 'task', t)">
          <span class="fa fa-fw"></span>&nbsp;
          <span>{{t.label | gnLocalized}}</span>
        </a>
      </li>
      <li role="menuitem" class="divider"
          data-ng-if="user.isConnected() && tasks.length > 0 && hasVisibletasks">&nbsp;</li>


      <li role="menuitem">
        <a href=""
           data-ng-if="user.isEditorOrMore() && md.draft != 'y'"
           data-ng-click="mdService.duplicate(md)">
          <span class="fa fa-fw fa-copy"></span>&nbsp;
          <span data-translate="">duplicate</span>
        </a>
      </li>
      <li role="menuitem">
        <a href=""
           data-ng-if="user.isEditorOrMore() && md.draft != 'y'"
           data-ng-click="mdService.createChild(md)">
          <span class="fa fa-fw fa-sitemap"></span>&nbsp;
          <span data-translate="">createChild</span>
        </a>
      </li>
    </ul>
  </div>
  <div class="btn-group md-actions">
    <button type="button"
            title="{{'downloadRecord' | translate}}"
            class="btn btn-default dropdown-toggle"
            data-toggle="dropdown"
            aria-label="{{'download' | translate}}"
            aria-expanded="false">
      <span class="fa fa-fw fa-download"></span>
      <span data-translate="" class="hidden-xs">download</span>
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
      <li data-ng-class="{'disabled': md.draft === 'y'}">
        <a href=""
           data-ng-click="mdService.getPermalink(md)">
          <span class="fa fa-fw fa-link"></span>&nbsp;
          <span data-translate="">permalink</span>
        </a>
      </li>
      <li role="menuitem" data-ng-repeat="f in formatterList">
        <a data-ng-href="../api/records/{{md.getUuid()}}{{f.url.replace('${lang}', lang)}}{{f.url.indexOf('?') !== -1 ? '&': '?'}}approved={{mdView.current.record.draft != 'y'}}"
           target="_blank">
          <span class="fa fa-fw {{f.class}}"></span>&nbsp;
          <span data-translate="">{{f.label | translate}}</span>
        </a>
      </li>

      <!-- TODO: RDF export should be replaced by a formatter. -->
      <li role="menuitem">
        <a href=""
           data-ng-click="mdService.metadataRDF(md.getUuid(), mdView.current.record.draft != 'y')">
          <span class="fa fa-fw fa-share-alt"></span>&nbsp;
          <span data-translate="">exportRDF</span>
        </a>
      </li>
    </ul>
  </div>
</div>
